# A tibble: 10 ร 2
region count
<chr> <int>
1 Western Europe 7
2 East Asia 5
3 Middle East 5
4 North America 5
5 South Asia 5
6 Africa 4
7 Eastern Europe 4
8 Latin America 4
9 Northern Europe 3
10 Oceania 2
Weekday Market Patterns
# Add this to the beginning of your load-market-data chunk
# Create a data directory if it doesn't exist
if (!dir.exists("data")) {
dir.create("data", showWarnings = FALSE)
}
# Define constants for data processing
MAX_RETURN_VALUE <- 20 # Cap at ยฑ20% for daily returns as a reasonable bound
MAX_REGIONAL_RETURN <- 5 # Cap at ยฑ5% for regional averages
WINSORIZE_PERCENTILE <- 0.005 # Winsorize at 0.5% on each tail
# Create a robust cache file path system for storing data
cache_file <- file.path("data", "global_market_data_cache_5yr.rds")
cache_file_weekly <- file.path("data", paste0("global_market_data_cache_5yr_", format(Sys.Date(), "%Y_%W"), ".rds"))
cache_file_daily <- file.path("data", paste0("global_market_data_cache_5yr_", format(Sys.Date(), "%Y_%m_%d"), ".rds"))
# Function to safely read cache files
safe_read_cache <- function(file_path) {
tryCatch({
if (file.exists(file_path)) {
message(paste("Attempting to load cache from:", file_path))
data <- readRDS(file_path)
# Basic validation
if (is.data.frame(data) && nrow(data) > 0 &&
all(c("date", "symbol", "close") %in% colnames(data))) {
message(paste("Successfully loaded cache with", nrow(data), "rows from", file_path))
return(data)
} else {
message("Cache data structure is invalid or empty")
}
}
return(NULL)
}, error = function(e) {
message(paste("Error reading cache file:", e$message))
return(NULL)
})
}
# Function to safely save cache
safe_save_cache <- function(data, file_path) {
tryCatch({
# Create directory if needed
dir.create(dirname(file_path), showWarnings = FALSE, recursive = TRUE)
# Save data
saveRDS(data, file_path)
message(paste("Successfully saved cache to:", file_path))
return(TRUE)
}, error = function(e) {
message(paste("Failed to save cache to:", file_path, "-", e$message))
return(FALSE)
})
}
market_data <- NULL
# Try to load from cache files in order of recency
if(is.null(market_data)) {
market_data <- safe_read_cache(cache_file_daily)
}
if(is.null(market_data)) {
market_data <- safe_read_cache(cache_file_weekly)
}
if(is.null(market_data)) {
market_data <- safe_read_cache(cache_file)
}
# If no cache, new code for fetching data will run as defined in your existing logic
Global Patterns: Is There a โBest Dayโ for Markets?
The chart below shows average returns by weekday across all global markets. Green bars show better performance, while red bars show weaker days.
Markets included in this analysis: ๐ฆ๐ช Abu Dhabi, ๐ฆ๐ท MERVAL Argentina, ๐ฆ๐บ S&P/ASX 200, ๐ง๐ท Bovespa, ๐จ๐ฆ S&P/TSX Composite, ๐จ๐ญ Swiss Market Index, ๐จ๐ฑ S&P CLX IPSA, ๐จ๐ณ CSI 300, ๐ฉ๐ช DAX 40, ๐ฉ๐ฐ OMX Copenhagen, ๐ช๐ฌ Egypt EGX 30, ๐ช๐ธ IBEX 35, ๐ช๐บ EURO STOXX 50, ๐ซ๐ท CAC 40, ๐ฌ๐ง FTSE 100, ๐ญ๐ฐ Hang Seng, ๐ฎ๐ฉ Jakarta Composite, ๐ฎ๐ณ BSE SENSEX, ๐ฎ๐ณ Nifty 50, ๐ฎ๐น FTSE MIB, ๐ฏ๐ต Nikkei 225, ๐ฐ๐ท KOSPI, ๐ฒ๐ฝ IPC Mexico, ๐ฒ๐พ Malaysia KLCI, ๐ณ๐ฌ Nigeria SE, ๐ณ๐ด Oslo Exchange, ๐ต๐ฑ Poland WIG, ๐ท๐บ MOEX Russia, ๐ธ๐ช OMX Stockholm, ๐ธ๐ฌ Straits Times, ๐น๐ท BIST 30, ๐น๐ผ Taiwan Weighted, ๐บ๐ธ Dow Jones, ๐บ๐ธ Nasdaq, ๐บ๐ธ Russell 2000, ๐บ๐ธ S&P 500, ๐ฟ๐ฆ JSE Top 40
Regional Comparison: Do Weekday Effects Vary by Region?
Different regions around the world show different weekday patterns, which may be influenced by local trading behavior, timezone differences, and market structure.
Check Your Marketโs Pattern
Different markets can show different patterns. Use the navigation arrows to explore weekday performance for each market:
Best and Worst Days by Region
The table below shows the best and worst performing weekdays for each region: